#pragma once

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <assert.h>

using namespace std;

namespace bit
{
	class string {
	public: 
		//迭代器实现
		typedef char* iterator;
		typedef const char* const_iterator;


		iterator begin();
		iterator end();

		const_iterator begin() const;
		const_iterator end() const;

		//string(); //无参构造
		//string(const char* str);
		string(const char* str = ""); //全缺省
		string(const string& s);
		//string& operator= (const string& s);
		string& operator= (string tmp);

		~string();

		const char* c_str() const;



		size_t size() const; //长度
		char& operator[](size_t pos); //打印
		const char& operator[](size_t pos) const; //打印

		void swap(string& s);

		void reserve(size_t n);

		void push_back(char ch);
		void append(const char* str);


		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos); //默认删除长度为-1
		
		size_t find(char ch,size_t pos = 0); //默认从0开始查找
		size_t find(const char* sub, size_t pos = 0);

		string substr(size_t pos = 0, size_t len = npos);

		bool operator<(const string& s) const;
		bool operator>(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>=(const string& s) const;
		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;

		void clear();
	private:
		// char _buff[16];
		char* _str;

		size_t _size = 0; //初始置为0，避免随机值
		size_t _capacity; // 初始置为0，避免随机值

		//特例
		//const static size_t npos = -1; //既是声明也是定义
		
		// 不支持
		//const static double N = 2.2; //浮点数不可以
		const static size_t npos;
	};

	istream& operator >> (istream& is, string& str);
	ostream& operator << (ostream& os, const string& str);


}